import socket, traceback, time, struct

host = ''
port = 51423

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))

while 1:
    try:
        message, address = s.recvfrom(8129)
        # 初始化 secs 变量，获取当前时间戳
        secs = int(time.time())
        # 调整时间戳，转换为 NTP 时间格式
        secs += 2208988800
        reply = struct.pack('!I', secs)
        s.sendto(reply, address)
    except(KeyboardInterrupt, SystemExit):
        raise
    except:
        traceback.print_exc()
